package com.blogSystem.article.util;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;

public class UpLoad {

  public  String upLoadFile(MultipartFile upload,HttpServletRequest request){
    String filePath="F:/blog_system/blog_system_web/src/main/resources/static/";

    String fileName=upload.getOriginalFilename();

    Date now=new Date();
    String salt=now.getTime()+"";
    String newFilePath=filePath+salt+fileName;
    String newFileName=salt+fileName;
    System.out.println(newFileName);
    try{
      upload.transferTo(new File(newFilePath));
      return newFileName;
    } catch (IOException e) {
      e.printStackTrace();
      return "error";
    }
  }
}

